﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pdm.Commons;
using Pdm.Solver;
using System.Diagnostics;

namespace Test
{
    public class Program
    {
        public static DmuList getSampleList()
        {
            DmuList dmus = new DmuList();
            dmus.Add(new Dmu("Prod1"));
            dmus.Add(new Dmu("Prod2"));
            dmus.Add(new Dmu("Prod3"));
            //dmus.Add(new Dmu("Prod4"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Input, "InputDummy"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Output, "Out1"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Output, "Out2"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Output, "Out3"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Output, "Out4"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Output, "Out5"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Output, "Out6"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Output, "Out7"));
            dmus.coefficients.Add(new Specification(Pdm.Commons.Type.Output, "Out8"));

            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[0], 1));
            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[1], 1.52380));
            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[2], 0.94117));
            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[3], 1.90909));
            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[4], 1.53846));
            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[5], 1.46666));
            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[6], 1.40909));
            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[7], 1.90625));
            dmus[0].coefficients.Add(new SpecificationInstance(dmus.coefficients[8], 1.61904));

            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[0], 1));
            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[1], 1.76190));
            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[2], 1.41176));
            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[3], 1.27272));
            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[4], 1.46153));
            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[5], 1.73333));
            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[6], 1.72727));
            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[7], 1.96875));
            dmus[1].coefficients.Add(new SpecificationInstance(dmus.coefficients[8], 2.04761));

            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[0], 1));
            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[1], 1.61904));
            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[2], 0.97058));
            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[3], 1.45454));
            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[4], 1.00000));
            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[5], 1.06666));
            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[6], 1.72727));
            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[7], 2.03125));
            dmus[2].coefficients.Add(new SpecificationInstance(dmus.coefficients[8], 1.76190));

           /* dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[0], 1));
            dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[1], 1.71904));
            dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[2], 0.87058));
            dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[3], 1.55454));
            dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[4], 1.20000));
            dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[5], 1.36666));
            dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[6], 1.12727));
            dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[7], 2.23125));
            dmus[3].coefficients.Add(new SpecificationInstance(dmus.coefficients[8], 1.76190));
            * */



            /*PdmOptimization pdm = new PdmOptimization(dmus, 0);
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[0], 11));
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[1], 21));
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[2], 34));
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[3], 11));
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[4], 13));
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[5], 15));
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[6], 22));
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[7], 32));
            pdm.urmWeights.Add(new SpecificationInstance(pdm.dmuList.coefficients[8], 21));
             */

            return dmus; 
           /* HeuristikSolver solv = new HeuristikSolver(pdm);
            pdm = solv.getOptimization(0.4d);

            foreach (SpecificationInstance inst in pdm.pdmWeights)
            {
                Debug.Print("pdmWeight " + inst.value);
            }
            Debug.WriteLine("eff " + pdm.efficiency);
            Debug.WriteLine("obj " + pdm.objectiveValue);
            Debug.WriteLine("pd " + pdm.profileDistance);
            */
        }

        static void Main(string[] args)
        {

            DmuList dmus = Program.getSampleList();
            //double[] urmWeights = new double[] { 1, 21, 34, 11, 13, 15, 22, 32, 21 };

            List<SpecificationInstance> urmWeights = new List<SpecificationInstance>();
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[0], 1));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[0], 11));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[1], 21));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[2], 34));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[3], 11));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[4], 13));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[5], 15));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[6], 22));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[7], 32));
            urmWeights.Add(new SpecificationInstance(dmus.coefficients[8], 21));


            //HeuristikSolver solver = new HeuristikSolver(dmus, dmus[0], urmWeights);

            Bisection bisec = new Bisection(dmus, dmus[0], urmWeights, Bisection.SolverModell.Heuristik, 0.1E-10);
            List<PdmOptimization> trans = bisec.getTransitions();
            Debug.WriteLine("SizeTrans: " + trans.Count);
            foreach(PdmOptimization opt in trans){
               Debug.WriteLine("PD " + opt.profileDistance);
               Debug.WriteLine("Alpha " + opt.alpha);
            }


        }
    }
}
